package com.joysuch.wwyt.workflow.repository;

import com.joysuch.wwyt.workflow.entity.WorkFlowMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.Tuple;
import java.util.List;

public interface WorkFlowMenuDao extends JpaRepository<WorkFlowMenu, Long>{


    public List<WorkFlowMenu> findAllByWorkFlowIdOrderByShowOrder(Long workFlowId);

    List<WorkFlowMenu> findAllByWorkFlowId(Long workFlowId);

    public void deleteAllByWorkFlowId(Long workFlowId);

    @Query(value = "select m.id, m.work_flow_id, m.menu_name, m.menu_url, m.menu_icon, m.parent_menu, m.show_order, p.system_id, p.system_name  " +
            " from wwyt_workflow_menu m, wwyt_workflow_process P " +
            " where  m.work_flow_id = p.id order by p.system_id, p.id, m.show_order ", nativeQuery = true)
    public List<Tuple> findMenuList();

    @Query(value = "select * from wwyt_workflow_menu  where task_names like %:taskName% limit 1 ", nativeQuery = true)
    public WorkFlowMenu findFirstByTaskNamesLike(@Param("taskName") String taskName);

    @Query(value = "select * from wwyt_workflow_menu where delete_flag = '0' and work_flow_id in :processIds and is_assign_user = :isAssignUser order by id desc", nativeQuery = true)
    List<WorkFlowMenu> findOptButtonsByWorkFlowId(@Param("processIds") List<Long> processIds, @Param("isAssignUser") int isAssignUser);

    List<WorkFlowMenu> findAllByParentMenuId(Long parentMenuId);
}
